﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace WaterMarkerApp
{
    public partial class BaseMainForm : BaseForm
    {

        #region private properties

        #endregion

        public BaseMainForm()
        {
            InitializeComponent();
            this.pnlMainForm.MouseMove += base.pnlMainForm_MouseMove;
            this.pnlMainForm.MouseUp += base.pnlMainForm_MouseUp;
            this.pnlMainForm.MouseDown += base.pnlMainForm_MouseDown;
        }

        #region Events

        private void lblButton_Click(object sender, EventArgs e)
        {
            Label currentLbl = sender as Label;
            if (currentLbl != null)
            {
                switch (currentLbl.Name)
                {
                    case "lblMenu":
                        cmsNavigation.Show(Cursor.Position);
                        break;
                    case "lblMini":
                        this.WindowState = FormWindowState.Minimized;
                        break;
                    case "lblClose":
                        CloseApp();
                        break;
                    case "lblIndex":
                        DisplayIndexForm();
                        break;
                }
            }
        }

        private void lblButton_MouseMove(object sender, MouseEventArgs e)
        {
            Label currentLbl = sender as Label;
            if (currentLbl != null)
            {
                switch (currentLbl.Name)
                {
                    case "lblMenu":
                        lblMenu.Image = global::WaterMarkerApp.Properties.Resources.导航缩略图按钮_1;
                        break;
                    case "lblMini":
                        lblMini.Image = global::WaterMarkerApp.Properties.Resources.窗口最小化按钮_1;
                        break;
                    case "lblClose":
                        lblClose.Image = global::WaterMarkerApp.Properties.Resources.窗口关闭按钮_1;
                        break;
                    case "lblIndex":
                        lblIndex.Image = global::WaterMarkerApp.Properties.Resources.窗口返回主页_1;
                        break;
                }
            }
        }

        private void lblButton_MouseLeave(object sender, EventArgs e)
        {
            Label currentLbl = sender as Label;
            if (currentLbl != null)
            {
                switch (currentLbl.Name)
                {
                    case "lblMenu":
                        lblMenu.Image = global::WaterMarkerApp.Properties.Resources.导航缩略图按钮;
                        break;
                    case "lblMini":
                        lblMini.Image = global::WaterMarkerApp.Properties.Resources.窗口最小化按钮;
                        break;
                    case "lblClose":
                        lblClose.Image = global::WaterMarkerApp.Properties.Resources.窗口关闭按钮;
                        break;
                    case "lblIndex":
                        lblIndex.Image = global::WaterMarkerApp.Properties.Resources.窗口返回主页;
                        break;
                }
            }
        }

        private void cmsNavigation_Click(object sender, EventArgs e)
        {
            bool openNewForm = true;
            ToolStripMenuItem currMenuItem = sender as ToolStripMenuItem;
            if (currMenuItem != null)
            {

                foreach (Form openedForm in Application.OpenForms)
                {
                    if (openedForm.Name == currMenuItem.Name)
                    {
                        openedForm.Activate();
                        openNewForm = false;
                        break;
                    }
                }
                if (openNewForm == true)
                {
                    BaseMainForm oForm = null;
                    switch (currMenuItem.Name)
                    {
                        case "AddWaterMarker":
                            oForm = new AddWaterMarker();
                            break;
                        case "CheckWaterMarker":
                            oForm = new CheckWaterMarker();
                            break;
                    }
                    if (oForm != null)
                    {
                        oForm.Show();
                        //MessageBox.Show(oForm.GetType().ToString());
                        //if (oForm.GetType() != typeof(IndexForm))
                        //{

                        //}
                        //else
                        //{
                        //    oForm.ShowDialog();
                        //}
                        //oForm.TopMost = true;
                    }
                }

            }
        }


        private void BaseMainForm_Load(object sender, EventArgs e)
        {
            ToolStripMenuItem importMenuItem = new ToolStripMenuItem("水印添加", global::WaterMarkerApp.Properties.Resources.水印添加, cmsNavigation_Click);
            importMenuItem.Name = "AddWaterMarker";
            cmsNavigation.Items.Add(importMenuItem);

            ToolStripMenuItem shelfMenuItem = new ToolStripMenuItem("水印检测", global::WaterMarkerApp.Properties.Resources.水印检测, cmsNavigation_Click);
            shelfMenuItem.Name = "CheckWaterMarker";
            cmsNavigation.Items.Add(shelfMenuItem);

            //ToolStripMenuItem publishMenuItem = new ToolStripMenuItem("盘片发行", global::MediaClient.Properties.Resources.发行_小图标, cmsNavigation_Click);
            //publishMenuItem.Name = "PrintForm";
            //cmsNavigation.Items.Add(publishMenuItem);

            //ToolStripMenuItem backMenuItem = new ToolStripMenuItem("视频输出", global::MediaClient.Properties.Resources.回放_小图标, cmsNavigation_Click);
            //backMenuItem.Name = "VideoOutputForm";
            //cmsNavigation.Items.Add(backMenuItem);

            //ToolStripMenuItem waterMarkerMenuItem = new ToolStripMenuItem("水印检测", global::MediaClient.Properties.Resources.检测_小图标, cmsNavigation_Click);
            //waterMarkerMenuItem.Name = "CheckWaterMarkerForm";
            //cmsNavigation.Items.Add(waterMarkerMenuItem);

            //ToolStripMenuItem sysMenuItem = new ToolStripMenuItem("系统设置", global::MediaClient.Properties.Resources.系统管理_小图标, cmsNavigation_Click);
            //sysMenuItem.Name = "SystemSettingForm";
            //cmsNavigation.Items.Add(sysMenuItem);

        }

        private void pnlMainForm_Paint(object sender, PaintEventArgs e)
        {

        }

        private void BaseMainForm_Load_1(object sender, EventArgs e)
        {
            ToolStripMenuItem importMenuItem = new ToolStripMenuItem("水印添加", global::WaterMarkerApp.Properties.Resources.水印添加, cmsNavigation_Click);
            importMenuItem.Name = "AddWaterMarker";
            cmsNavigation.Items.Add(importMenuItem);

            ToolStripMenuItem shelfMenuItem = new ToolStripMenuItem("水印检测", global::WaterMarkerApp.Properties.Resources.水印检测, cmsNavigation_Click);
            shelfMenuItem.Name = "CheckWaterMarker";
            cmsNavigation.Items.Add(shelfMenuItem);
        }
        #endregion


        #region private methods
        private void CloseApp()
        {
            if (Application.OpenForms.Count == 1)
            {
                Process.GetCurrentProcess().Close();
                Process.GetCurrentProcess().Dispose();
                Process.GetCurrentProcess().Kill();
            }
            else
            {
                this.Close();
                this.Dispose();
                DisplayIndexForm();
            }
        }

        private void DisplayIndexForm()
        {
            foreach (Form openedForm in Application.OpenForms)
            {
                if (openedForm.Name == "IndexForm")
                {
                    openedForm.Activate();
                    openedForm.Visible = true;
                    break;
                }
            }
        }
        #endregion



       


    }
}
